Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PrintfParametersRule #3247

Merged
merged 1 commit into from
Jul 16, 2024
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 16, 2024

extracted from #3126

factor out PrintfHelper for later re-use in a to be created PrintfArrayParametersRule

@staabm staabm marked this pull request as ready for review July 16, 2024 07:03
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

Comment on lines +21 to +29
public function getPrintfPlaceholdersCount(string $format): int
{
return $this->getPlaceholdersCount('(?:[bs%s]|l?[cdeEgfFGouxX])', $format);
}

public function getScanfPlaceholdersCount(string $format): int
{
return $this->getPlaceholdersCount('(?:[cdDeEfinosuxX%s]|\[[^\]]+\])', $format);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this use-cases separated because I only need the getPrintfPlaceholdersCount in PrintfArrayParametersRule

return [];
}

$formatArgumentPosition = $functionsArgumentPositions[$name];
$functionReflection = $this->reflectionProvider->getFunction($node->name, $scope);
Copy link
Contributor Author

@staabm staabm Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was one of the few rules which did not validate the $node->name via ReflectionProvider.

I guess its not strictly necessary because we are handling php-src native functions - I added it for consistency.

@ondrejmirtes ondrejmirtes merged commit 14d0951 into phpstan:1.11.x Jul 16, 2024
451 of 456 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the printf-refac branch July 16, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants